<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title id="htm_title"></title>
    <script type="text/javascript" src="https://cdn.bootcss.com/jquery/1.8.3/jquery.js"></script>
    <script type="text/javascript">
        var load_user = "{$Request.session.user}";
        var m_id = getUrlParam('mid');
        var id = getUrlParam('id');
        $(document).ready(function () {
            setpage();
            if (load_user !== "") {
                $("#load_message").html(load_user + "|<a href='/forum/index.php/user/logout'>注销</a>");
                editor.enable();
            }else {
                editor.disable();
                $("#wangEdit").append("<a href='/forum/index.php/user/login' style='margin-left: 45%'>登录后回复</a>")
            }
        })
        function setpage(page) {
            $.ajax({
                url: "/forum/index.php/thread/read/read",
                type: "post",
                data: {"m_id": m_id, "id": id,"p":page},
                dataType: "json",
                success: function (data) {
                    $("#thread_title").html("标题：" + data.read.title);
                    $("#thread_content").html(data.read.context);
                    $("#htm_title").html(data.read.title);
                    $("#thread_name").html(data.read.name);
                    $("#head_list").html(data.head);
                    $("#thread_time").html(data.read.first_time);
                    $("#thread_photo").append("<img src='/forum"+data.read.photo+"'>")
                    var aaa=data.read.reg_date
                    $("#thread_ucount").append("积分:"+data.read.score+"</br>注册:"+aaa.substr(0,10))
                    $("#page_banner").html(data.banner);
                    $("#reply_list").empty();
                    page=!page?1:page;
                    var louceng=(page-1)*20;
                    if(data.total==0){
                        $("#page_banner").empty();
                    }
                    $.each(data.reply,function () {
                        louceng+=1;
                        var bbb=this.reg_date
                        $("#reply_list").append("<div class='post-top'></div><div class='bbox'><div class='buinfo'><div class='uimg'><img src='/forum"+this.photo+"'></div><div class='uflag'>"+this.name+"</div><div class='ucount'>积分:"+this.score+"</br>注册:"+bbb.substr(0,10)+"</div></div><div class='bmain'><div class='bmtop'><div class='bmtleft'>发表于: <span>"+this.first_time+"</span></div><div class='bmtright'>"+louceng+"#</div></div><div class='bmcontent'>"+this.context+"</div><div class='bmqianming'>伟大是熬出来的，编程是逼出来的！</div><div class='bmtips'></div><div class='bmbt'><div class='bmbtleft'>回复本楼</div><div class='bmbtright'>举报</div></div></div> <div style='clear:both'></div></div>");
                    })
                    if (page>1) {
                        $("html,body").animate({scrollTop: $("#reply_list").offset().top}, 10)
                    }
                },
                error: function (jqXHR) {
                    alert("Ajax错误！" + jqXHR.status);
                }
            })
        }
        //获取url中的参数
        function getUrlParam(name) {
            var reg = new RegExp("(^|&)" + name + "=([^&]*)(&|$)"); //构造一个含有目标参数的正则表达式对象
            var r = window.location.search.substr(1).match(reg);  //匹配目标参数
            if (r != null)
                return unescape(r[2]);
            return null; //返回参数值
        }

        function reply() {
            if (!load_user){
                alert("请先登录，再进行回复！");
            }else {
                var context=editor.$txt.html();
                $.post("/forum/index.php/thread/reply",{"context":context,"name":load_user,"z_id":id},function (data) {
                    alert(data);
                    window.location.reload();
                })
            }
        }

        function search(page) {
            var kw=$("#kw").val();
            window.location.href='/forum/index.php/thread/search/search?kw='+kw
        }
    </script>
    <link rel="stylesheet" href="/forum/public/static/css/forum/forum.css">
    <link rel="stylesheet" href="/forum/public/static/css/forum/public.css">
    <link rel="stylesheet" href="/forum/public/static/css/forum/thread.css">
</head>
<body>
<div class="top-bar">
    <div class="main">
        <div class="t_u" id="load_message">
            <a href="/forum/index.php/user/register.html">注册</a>
            |
            <a href="/forum/index.php/user/login.html" id="login">登录</a>
        </div>
    </div>
</div>
<div class="forum_path" id="head_list"></div>
<div class="forum_path">
    <input type="text" id="kw" style="width: 40%;">
    <input type="image" src="/forum/public/static/pic/search.jpg" onclick="search()">
</div>
<div class="forum_style">
    <li id="thread_title">
    </li>
</div>

<div class="bbox">
    <div class="buinfo">
        <div class="uimg" id="thread_photo"></div>
        <div class="uflag" id="thread_name"></div>
        <div class="ucount" id="thread_ucount">
        </div>
    </div>
    <div class="bmain">
        <div class="bmtop">
            <div class="bmtleft">发表于: <span id="thread_time"></span> |只看该作者 |倒序浏览</div>
            <div class="bmtright">楼主</div>
        </div>
        <div class="bmcontent" id="thread_content"></div>
        <div class="bmqianming">伟大是熬出来的，编程是逼出来的！</div>
        <div class="bmtips"></div>
        <div class="bmbt">
            <div class="bmbtleft"><a href="#wangEdit">回复楼主</a></div>
            <div class="bmbtright">举报</div>
        </div>
    </div>
    <div style="clear:both"></div>
</div>
<div id="reply_list"></div>
<div class="forum_top">
    <ul class="page_num" id="page_banner">
    </ul>
</div>
<div class="post-top">发表回复</div>
<div style="width: 960px;margin: auto">
    <div id="wangEdit" style="height: 300px;max-height: 800px"></div>
</div>
<div class="post-top">
    <input id="reply" type="image" src="/forum/public/static/pic/re.gif" onclick="reply()">
</div>


<!--
<div class="forum_path">
</div>

<div class="bbox">
    <div class="buinfo">
        <div class="uimg">
            <img src="/forum/public/static/pic/tx.gif"/>
        </div>
        <div class="uflag" id="thread_name">
        </div>
        <div class="ucount">
        </div>
    </div>
    <div class="bmain">
         <div class="bmcontent" id="thread_content">
        </div>
        <div class="bmqianming">

        </div>
        <div class="bmtips">

        </div>
        <div class="bmbt">
            <div class="bmbtleft">回复</div>
            <div class="bmbtright">举报</div>
        </div>
    </div>
</div>
<div class="post-top">发表回复</div>
-->
</body>
</html>
<script src="/forum/public/static/vendor/wangEditor/dist/js/wangEditor.min.js"></script>
<link rel="stylesheet" href="/forum/public/static/vendor/wangEditor/dist/css/wangEditor.min.css">
<script type="text/javascript">
    var editor = new wangEditor('wangEdit');
    editor.create();
</script>